package controller

import (
	"core/service"

	"github.com/gin-gonic/gin"
)

type CreateLibraryNodeRequest struct {
	DSL  string `json:"dsl"`
	Name string `json:"name"`
}

func createLibraryNode(c *gin.Context) {
	var createLibraryNodeRequest CreateLibraryNodeRequest

	err := c.BindJSON(&createLibraryNodeRequest)
	if err != nil {
		SendError(c, err)
		return
	}

	err = service.CreateHubNodeDefintion(createLibraryNodeRequest.DSL,
		createLibraryNodeRequest.Name)
	if err != nil {
		SendError(c, err)
		return
	}

	SendData(c, nil)
}

func NodesRegister(r *gin.Engine) {
	r.POST("/library/nodes", createLibraryNode)
}
